package com.vk.project.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.vk.project.common.ErrorCode;
import com.vk.project.exception.BusinessException;
import com.vk.project.mapper.InterfaceInfoMapper;
import com.vk.vkapicommon.model.entity.InterfaceInfo;
import com.vk.vkapicommon.service.InnerInterfaceInfoService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;

/**
 * @ClassName : InnerInterfaceInfoServiceImpl
 * @Description : 内部接口服务实现类
 * @Author : LYQ
 * @Date: 2023-11-23 22:07:58
 */
@DubboService
public class InnerInterfaceInfoServiceImpl implements InnerInterfaceInfoService {

    @Autowired
    private InterfaceInfoMapper interfaceInfoMapper;

    /**
     * 获取接口信息
     *
     * @param path    接口路径
     * @param method 接口调用的方法类型
     * @return 返回接口的信息
     */
    @Override
    public InterfaceInfo getInterfaceInfo(String path, String method) {
        // 检验参数是否为空
        if (StringUtils.isAnyBlank(path, method)) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        QueryWrapper<InterfaceInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("path", path);
        queryWrapper.eq("method", method);
        // 根据Url,调用的方法类型查询对应的接口信息
        return interfaceInfoMapper.selectOne(queryWrapper);
    }
}
